#ifndef __STACK_H_
#define __STACK_H_


#define STACK_MAXSIZE 64  //栈的容量，自定义 

typedef struct
{
    int data[STACK_MAXSIZE];
    int top;
}stack;

//初始化栈,清空栈 
int stackInit(stack *s)
{
    if(s != NULL)
    {
        s->top=-1;
        return 1;
    }
    return 0;
}

//判断栈是否为空 
int stackIsEmpty(stack *s)
{
    if(s != NULL && s->top==-1)
    {
        return 1;
    }
    return 0;
}

//判断栈是否已满
int stackIsFull(stack *s)
{
    if(s != NULL && s->top==STACK_MAXSIZE-1)
    {
        return 1;
    }
    return 0;
}

//进栈 
int stackPush(stack *s, int value)//若栈未满，将元素x入栈s 中；否则提示出错信息
{
    if(stackIsFull(s))
    {
        printf("push error: overflow\n");
        return 0;
    }
    s->top++;
    s->data[s->top]=value;
    return 1;
}

//出栈 
int stackPop(stack *s, int *value)
{
    if(stackIsEmpty(s))
    {
        printf("pop error: underflow\n");
        return 0;
    }
    *value = s->data[s->top];
    s->top--;
    return 1;
}

//查看栈顶元素
int peek(stack *s, int *value)/*取栈顶元素，栈顶元素通过参数 返回*/
{
    if(stackIsEmpty(s))
    {
        printf("peek error: stack is empty\n");
        return 0;
    }
    *value = s->data[s->top];
    return 1;
}

#endif



